package structure;

import java.util.ArrayList;

public class NonTerminal {
	
	private String[] aplphabet= {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", 
								 "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};
	private int index;
	private String nonTerminal;
	private String currentNT;
	private ArrayList<String> VN;
	ArrayList<String> used;
	
	public NonTerminal(ArrayList<String> VN){
		
		this.index= 0;
		this.nonTerminal= "";
		this.currentNT= "";
		this.VN= VN;
		this.used= new ArrayList<String>();
		
		this.getCharacter();
		
		this.currentNT= this.nonTerminal;
	}
	
	public void getCharacter(){

		for(String s : this.aplphabet){
			
			if(!this.VN.contains(s) && !this.used.contains(s)) {
				this.nonTerminal= s;
				this.used.add(s);
				break;
			}
		}
	}

	public void getCharacterDifferentFrom(String a){

		for(String s : this.aplphabet){
			
			if(!this.VN.contains(s) && !s.equals(a) && !this.used.contains(s)) {
				this.nonTerminal= s;
				break;
			}
		}
	}
	
	public String getNewTmpNT(){
		
		if(this.index == 10){
			
			this.index= 0;
			this.getCharacterDifferentFrom(this.nonTerminal);
		}
		
		String toReturn= this.nonTerminal + Integer.toString(this.index);
		this.currentNT= toReturn;
		this.index++;
		
		return toReturn;
	}
	
	public String getCurrentNT(){
		
		return this.currentNT;
	}
	
	
	public boolean AlreadyExist(String vn, ArrayList<String> VN){
		
		return VN.contains(vn);
	}
	
	public int getCurrentIndex(){
		
		return this.index;
	}
}
